package com.eastfair.venuebooking.controller;

import com.eastfair.annotation.annotation.log.SysLog;
import com.eastfair.annotation.annotation.security.PreAuth;
import com.eastfair.venuebooking.dto.*;
import com.eastfair.venuebooking.entity.PriceList;
import com.eastfair.venuebooking.service.PriceListService;

import java.text.ParseException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.eastfair.boot.controller.SuperController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.echo.core.EchoService;
import com.eastfair.core.base.R;
import com.eastfair.venuebooking.vo.PriceListVO;
import com.eastfair.venuebooking.vo.SpaceVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.eastfair.boot.request.PageParams;
import com.eastfair.core.context.ContextUtil;


/**
 * <p>
 * 前端控制器
 * 价目表
 * </p>
 *
 * @author linan
 * @date 2022-06-08
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/priceList")
@Api(value = "PriceList", tags = "价目表")
@PreAuth(replace = "venuebooking:priceList:")
public class PriceListController extends SuperController<PriceListService, Long, PriceList, PriceListPageQuery, PriceListSaveDTO, PriceListUpdateDTO> {

    @Autowired
    private EchoService echoService;
    @Autowired
    private PriceListService priceListService;

    @Override
    public void handlerResult(IPage<PriceList> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }



    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<PriceList> priceListList = list.stream().map((map) -> {
            PriceList priceList = PriceList.builder().build();
            //TODO 请在这里完成转换
            return priceList;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(priceListList));
    }



    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<PriceListPageQuery> params) {
        PriceListPageQuery pageQuery = params.getModel();
        //分页处理
        if(ContextUtil.getProjectId()!=null){
            pageQuery.setProjectId(ContextUtil.getProjectId());
        }
    }

    /**
     * 查询价目表列表
     * @param params
     * @return
     */
    @ApiOperation(value = "查询价目表列表")
    @PostMapping(value = "/queryPriceList")
    public R<IPage<PriceListVO>> queryPriceList(@RequestBody PageParams<PriceListPageQuery> params) {
        IPage<PriceListVO> page = priceListService.queryPriceList(params);
        return R.success(page);
    }


    /**
     * 添加价目表信息
     * @return}
     */
    @ApiOperation(value = "添加价目表信息")
    @SysLog("添加价目表")
    @PostMapping(value = "/savePriceListInfo")
    public R<Boolean> savePriceListInfo(@RequestBody @Validated(PriceListSaveDTO.Save.class) PriceListSaveDTO priceListSaveDTO){
        return R.success(priceListService.savePriceListInfo(priceListSaveDTO));
    }

    /**
     * 修改价目表信息
     * @return}
     */
    @ApiOperation(value = "修改价目表信息")
    @SysLog("修改价目表")
    @PostMapping(value = "/updatePriceListInfo")
    public R<Boolean> updatePriceListInfo(@RequestBody  @Validated(PriceListUpdateDTO.Update.class) PriceListUpdateDTO priceListUpdateDTO){

        return R.success(priceListService.updatePriceListInfo(priceListUpdateDTO));
    }

    /**
     * 删除价目表信息
     * @param priceListUpdateDTOList
     * @return
     */
    @SysLog("删除价目表")
    @PostMapping("/delPriceListByIds")
    public R<Boolean> delPriceListByIds(@RequestBody List<PriceListUpdateDTO> priceListUpdateDTOList) {
        return R.success(priceListService.delPriceListByIds(priceListUpdateDTOList));
    }











}
